
package com.e885.service;

import java.lang.reflect.Field;

/**
 * Common Service
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public abstract class CommonService
{
	/**
	 * 預設每頁筆數為 10 筆
	 */
	public static int DEFAULT_PAGE_SIZE = 10;

	/**
	 * 檢查是否為 null
	 * 
	 * @param value
	 * @param name
	 */
	protected static void validNull( Object value, String name )
	{
		if( value == null )
			throw new IllegalArgumentException( name + " is null" );
	}

	/**
	 * 檢查參數的 bean 是否為 null
	 * 
	 * @param bean
	 */
	protected static void validNull( Object bean )
	{
		validNull( bean, "bean" );

		Field[] fields = bean.getClass().getDeclaredFields();

		int size = fields.length;

		for( int i = 0; i < size; i++ )
		{
			try
			{
				fields[ i ].setAccessible( true );

				validNull( fields[ i ].get( bean ), fields[ i ].getName() );
			}
			catch( IllegalArgumentException e )
			{
				e.printStackTrace();
			}
			catch( IllegalAccessException e )
			{
				e.printStackTrace();
			}
		}
	}
}
